<template>
  <div>
    <el-card>
      <el-row>
        <span style="font-size: 23px;font-weight: bold">入驻企业管理</span>
        <div class="custom-tabs ml20">
          <div class="custom-tab-btn"
               :class="{ active: state.tabs === 'unaudited' }"
               @click="page.handleClickTabs('unaudited')">
            待审核
          </div>
          <div class="custom-tab-btn"
               :class="{ active: state.tabs === 'audited' }"
               @click="page.handleClickTabs('audited')">
            已审核
          </div>
        </div>
      </el-row>
    </el-card>
    <div style="padding: 20px">
      <el-card>
        <el-row style="display: flex;align-items: center;padding: 15px 0px 15px 0px">
          <span>企业名称：</span>
          <el-input placeholder="请输入企业名称"
                    class="w-200"
                    v-model="state.where.orgName"/>
          <span class="ml10"  v-if="state.tabs === 'unaudited'">审核状态：</span>
          <el-select v-model="state.where.approveStatus" placeholder="请选择审核状态"
                     v-if="state.tabs === 'unaudited'"
                     style="width:140px;margin-left: 10px;">
            <el-option v-for="item in approveStatus" :key="item.value" :label="item.text"
                       :value="item.value"/>
          </el-select>
          <el-button class="btn ml10"
                     type="primary"
                     @click="page.load()">
            <el-icon>
              <elementSearch/>
            </el-icon>
            搜索
          </el-button>
          <el-button class="btn" @click="page.reset()">
            <el-icon>
              <elementRefreshRight/>
            </el-icon>
            重置
          </el-button>
        </el-row>
        <template v-if="state.tabs === 'unaudited'">
          <ld-table ref="tableRef"
                        url="/api/entEntry/apply/query/page"
                        :columns="settledEnterprise.unaudited"
                        :where="state.where"
                        :isTableTitle="false"
                        :isShowData="true"
                        :isPage="true">
            <template v-slot:approveStatus="attr">
              <span>{{ getApproveStatus(attr.row.approveStatus) }}</span>
            </template>
            <template #orgName="scope">
              <span style="cursor: pointer" @click="page.openForm({id:scope.row.id})">{{ scope.row.orgName }}</span>
            </template>
            <template #action="scope">
              <el-link class="ml10"
                       size="small"
                       type="primary"
                       :underline="false"
                       @click="page.openForm({id:scope.row.id})">
                审核
              </el-link>
<!--              <el-link class="ml10"-->
<!--                       size="small"-->
<!--                       type="danger"-->
<!--                       :underline="false"-->
<!--                       @click="page.openReturnDialog()">-->
<!--                退回-->
<!--              </el-link>-->
            </template>
          </ld-table>
        </template>
        <template v-if="state.tabs === 'audited'">
          <ld-table ref="tableRef"
                        url="/api/entEntry/apply/query/page"
                        :columns="settledEnterprise.audited"
                        :where="state.where"
                        :isTableTitle="false"
                        :isShowData="true"
                        :isPage="true">
            <template v-slot:approveStatus="attr">
              <span>{{ getApproveStatus(attr.row.approveStatus) }}</span>
            </template>
            <template #orgName="scope">
              <span style="cursor: pointer" @click="page.openForm({id:scope.row.id})">{{ scope.row.orgName }}</span>
            </template>
          </ld-table>
        </template>
      </el-card>
    </div>
    <ReturnFormDialog ref="returnDialogRef" @submit="page.handleSubmitReturnReason" @close="page.handleDialogClose"/>
  </div>
</template>
<script lang="ts" setup>
import {reactive, getCurrentInstance, ref, onMounted} from "vue";
import {useRouter, useRoute} from "vue-router";
import {settledEnterprise} from "./dictionary/column";
import ReturnFormDialog from "/@/views/enterpriseManager/component/returnFormDialog.vue";
import {getApproveStatus, approveServiceStatus, approveStatus} from "../common/dictionary";
import {approveMark} from "/@/views/enterpriseManager/dictionary/constant";

const returnDialogRef = ref<{ openDialog: () => void }>();
const {proxy} = getCurrentInstance() as any;
const router = useRouter();
const route = useRoute();
const tableRef = ref();

const state = reactive({
  tabs: "unaudited",
  tabShow: {
    unaudited: true,
    audited: false
  },
  where: {
    orgName: "",
    type: "",
    approveStatus:"",//审批状态
    orderColumn: "create_time",
    orderFormat: "desc"
  },
});
const page = {
  reset: () => {
    state.where.orgName = "";
  },
  load: () => {
    tableRef.value.load();
  },
  delete: (keyValue: string) => {
    proxy.$wigem.confirm("是否删除？").then((res) => {
      // deleteEnterprise(keyValue).then((res) => {
      //   if (res.success) {
      //     proxy.$wigem.alert.success(res.msg);
      //     page.load()
      //   } else {
      //     proxy.$wigem.alert.error("保存失败");
      //   }
      // })
    });
  },
  openForm: (params: object) => {
    router.push({
      name: "settledEnterpriseForm",
      query: params
    })
  },
  openReturnDialog: () => {
    returnDialogRef.value?.openDialog(approveMark.RETURN_FOR_MODIFY);
  },
  handleSubmitReturnReason: (reason: string) => {
    console.log('提交的退回原因:', reason);
  },
  handleDialogClose: () => {
    console.log('退回原因弹窗已关闭');
  },
  handleClickTabs:(tabsName:string)=>{
    state.tabs = tabsName;
    tabsName == "unaudited" ? state.where.approveStatus = "" : state.where.approveStatus = "7";
  }
};

onMounted(() => {
});

</script>
<style lang="scss" scoped>

::v-deep(.el-card__body) {
  padding: 10px 20px 0 30px;
}

.custom-tabs {
  display: flex;
  gap: 10px;
  font-size: 20px;

  .custom-tab-btn {
    padding: 8px 16px;
    border: none;
    cursor: pointer;
    transition: all 0.3s;
  }

  .custom-tab-btn.active {
    color: #409eff;
    border-bottom: 2px solid #409eff;
  }
}
</style>
